package com.gmrz.uap.config;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Wang Haifeng
 */
public class SentinelConfig {

    private static final Logger log = LoggerFactory.getLogger(SentinelConfig.class);


    private SentinelConfig() {
    }

    public static void configureFlowRules() {
        List<FlowRule> rules = new ArrayList<>();
        FlowRule rule = new FlowRule();
        rule.setResource("reg_receive");
        rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        rule.setCount(2);
        rules.add(rule);

        log.info("SentinelConfig configureFlowRules:{}", rules);

        FlowRuleManager.loadRules(rules);
    }
}
